package com.guanghua.brick.html.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.guanghua.brick.html.IControl;

public class DataSourceTag extends BodyTagSupport {
	
	private static Log logger = LogFactory.getLog(DataSourceTag.class);
	
	public int doEndTag() throws JspException {
		//找到父亲，并add data
		Tag tag = this.getParent();
		if (tag instanceof IControl && bodyContent != null) {
			String dataSource = bodyContent.getString();
			if (dataSource != null) ((IControl)tag).setDataSource(dataSource.trim());
		} else {
			logger.warn("datasource parent must be Icontrol and must be have body content");
		}
		return BodyTagSupport.EVAL_PAGE;
	}
}
